package com.hig.risk.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.risk.domain.RiskSelfInspectionContent;
import com.hig.risk.service.IRiskSelfInspectionContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排查内容Controller
 * 
 * @author scp
 * @date 2024-11-23
 */
@RestController
@RequestMapping("/risk/content")
public class RiskSelfInspectionContentController extends BaseController
{
    @Autowired
    private IRiskSelfInspectionContentService riskSelfInspectionContentService;

    /**
     * 查询排查内容列表
     */
    @PreAuthorize("@ss.hasPermi('risk:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskSelfInspectionContent riskSelfInspectionContent)
    {
        startPage();
        List<RiskSelfInspectionContent> list = riskSelfInspectionContentService.selectRiskSelfInspectionContentList(riskSelfInspectionContent);
        return getDataTable(list);
    }

    /**
     * 导出排查内容列表
     */
    @PreAuthorize("@ss.hasPermi('risk:content:export')")
    @Log(title = "排查内容", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RiskSelfInspectionContent riskSelfInspectionContent)
    {
        List<RiskSelfInspectionContent> list = riskSelfInspectionContentService.selectRiskSelfInspectionContentList(riskSelfInspectionContent);
        ExcelUtil<RiskSelfInspectionContent> util = new ExcelUtil<RiskSelfInspectionContent>(RiskSelfInspectionContent.class);
        return util.exportExcel(list, "排查内容数据");
    }

    /**
     * 获取排查内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('risk:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskSelfInspectionContentService.selectRiskSelfInspectionContentById(id));
    }

    /**
     * 新增排查内容
     */
    @PreAuthorize("@ss.hasPermi('risk:content:add')")
    @Log(title = "排查内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskSelfInspectionContent riskSelfInspectionContent)
    {
        return toAjax(riskSelfInspectionContentService.insertRiskSelfInspectionContent(riskSelfInspectionContent));
    }

    /**
     * 修改排查内容
     */
    @PreAuthorize("@ss.hasPermi('risk:content:edit')")
    @Log(title = "排查内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskSelfInspectionContent riskSelfInspectionContent)
    {
        return toAjax(riskSelfInspectionContentService.updateRiskSelfInspectionContent(riskSelfInspectionContent));
    }

    /**
     * 删除排查内容
     */
    @PreAuthorize("@ss.hasPermi('risk:content:remove')")
    @Log(title = "排查内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskSelfInspectionContentService.deleteRiskSelfInspectionContentByIds(ids));
    }

    @GetMapping("/allList")
    public AjaxResult allList(RiskSelfInspectionContent riskSelfInspectionContent)
    {
        List<RiskSelfInspectionContent> list = riskSelfInspectionContentService.selectAllContentList(riskSelfInspectionContent);
        for (RiskSelfInspectionContent content : list){
            content.setInspectionProject(content.getId());
        }
        return AjaxResult.success(list);
    }

    @GetMapping("/allList/{id}")
    public AjaxResult queryByBasis(@PathVariable("id") String id)
    {
        RiskSelfInspectionContent riskSelfInspectionContent = new RiskSelfInspectionContent();
        riskSelfInspectionContent.setRemarkSpare(id);
        List<RiskSelfInspectionContent> list = riskSelfInspectionContentService.selectRiskSelfInspectionContentList(riskSelfInspectionContent);
        return AjaxResult.success(list);
    }
}
